package com.yd.mvc.baseController.util;

import com.yd.app.util.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.method.HandlerMethod;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by zq on 2015/12/3.
 */
@Service("exceptionCallbackImpl")
public class ExceptionCallbackImpl implements ExceptionHandlerCallback {
    protected static final Logger LOGGER = LoggerFactory.getLogger(ExceptionCallbackImpl.class);
    @Override
    public void callback(HttpServletRequest request, HttpServletResponse httpServletResponse, Object handler, Exception e) {
        if(e==null) return;
        try{
            if(e instanceof BusinessException){
                return;
            }
            String module="";
            if(handler instanceof HandlerMethod){
                HandlerMethod method = (HandlerMethod) handler;
                module= method.getBean().getClass().getName()+"--"+method.getMethod().getName();
            }
            String msg=e.getMessage();
           /* if(e instanceof SystemException){
                e=((SystemException) e).getOriginalException();
            }*/
        }catch (Exception ex){
            LOGGER.error(ex.getMessage(),ex);
        }

    }

}
